<?php

namespace app\admin\controller;

use app\admin\model\Advertise;
use app\admin\model\Advertiselocal;
use app\admin\model\Askpricerecord;
use app\admin\model\Store;
use app\admin\model\Ticket;
use app\admin\model\Type;
use app\admin\model\User;
use app\admin\model\Member;

class HomeFrame extends Base
{

    // 首页数据
    public function getHomeFrame()
    {
        $param = self::getHttpParam();

        $defaultWhere = $this->getDefaultWhere();
        $where = $defaultWhere;

        // 店铺
        $store = $this->getStore($where);

        // 优惠券
        $ticket = $this->getTicket([]);

        // 分销会员
        $user = $this->getUser([]);

        // 装修业主
        $askpricerecord = $this->getAskpricerecord($where);

        // 订单
        $order = $this->getOrder($where);

        // 广告
        $advertise = $this->getAdvertise($where);

        // 分类
        $type = $this->getType($where);


        $data = [
            'store' => $store ? : '',
            'ticket' => $ticket ? : '',
            'user' => $user ? : '',
            'askpricerecord' => $askpricerecord ? : '',
            'order' => $order ? : '',
            'advertise' => $advertise ? : '',
            'type' => $type ? : '',
        ];

        return show(config('status.SUCCESS_STATUS'), self::MSG_SUCCESS, $data);
    }

    public function getStore($where){
        $where['status'] = 0;
        $count = Store::where($where)->count();
        $data = [
            'count' => $count,
        ];

        return $data;
    }

    public function getTicket($where){
        $where['a.status'] = 4;
        if($this->admin->roleType != 1){
            $where['s.province'] = $this->admin->province;
            if($this->admin->city != '所有') {
                $where['s.city'] = $this->admin->city;
            }
        }
        $join = [
            ['store s', 's.id = a.storeId'],
        ];
        $count = Ticket::alias('a')->where($where)->join($join)->count();
        $data = [
            'count' => $count,
        ];

        return $data;
    }

    public function getUser($where){
        $where['a.status'] = 0;
        $where['a.phone'] = [['neq', ''], ['neq', 'null'], 'and'];
        if($this->admin->roleType != 1){
            $where['s.province'] = $this->admin->province;
            if($this->admin->city != '所有') {
                $where['s.city'] = $this->admin->city;
            }
        }
        $join = [
            ['storeuser su', 'su.userId = a.id'],
            ['store s', 's.id = su.storeId']
        ];
        $count = Member::alias('a')->where($where)->join($join)->count();
        $data = [
            'count' => $count,
        ];

        return $data;
    }

    public function getAskpricerecord($where){
        return [];
    }

    public function getOrder($where){
        return [];
    }

    public function getAdvertise($where){
        return [];
    }

    public function getType($where){
        return [];
    }

}